home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amiga / muibuilder / mb / developer / c / sources_gencodec / writeguifiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-16  |  21.8 KB  |  891 lines

  1. #include "WriteGUIFiles.h"
  2. #include "MB_protos.h"
  3. #include "MB_pragmas.h"
  4. #include "mb.h"
  5. #include "MB_MUI_Strings.h"
  6. #include "Tools.h"
  7.  
  8. #include <exec/types.h>
  9. #include <clib/exec_protos.h>
  10. #include <clib/dos_protos.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13.  
  14. extern void Quit(void);
  15.  
  16. extern struct Library * MUIBBase;
  17.  
  18. /* variable types */
  19. static char    *STR_type[] =
  20. {
  21.     "BOOL",
  22.     "int",
  23.     "char *",
  24.     "char *",
  25.     "APTR",
  26.     "",
  27.     "",
  28.     "",
  29.     "APTR",
  30.     "APTR"
  31. };
  32.  
  33. /****************************************************************************************************************/
  34. /*****                                                                                                        *****/
  35. /**                                                WriteParameters                                                **/
  36. /*****                                                                                                        *****/
  37. /****************************************************************************************************************/
  38.  
  39. static void WriteParameters(FILE *file,ULONG varnb,BOOL Notifications)
  40. {
  41.     int   i;
  42.     char  *varname, *typename;
  43.     ULONG type,size;
  44.     BOOL  comma = FALSE;
  45.   
  46.     typename = STR_type[ TYPEVAR_EXTERNAL_PTR - 1 ];
  47.     if (Notifications)
  48.     {
  49.         for(i=0;i<varnb;i++)
  50.         {
  51.             MB_GetVarInfo (i,
  52.                            MUIB_VarType, &type,
  53.                            MUIB_VarName, &varname,
  54.                            MUIB_VarSize, &size,
  55.                            TAG_END
  56.                           );
  57.     
  58.             if (type == TYPEVAR_EXTERNAL_PTR)
  59.             {
  60.                 if (comma)
  61.                      fprintf(file, ", ");
  62.  
  63.                 comma = TRUE;
  64.                 fprintf(file, "%s %s", typename, varname);
  65.             }
  66.         }
  67.     }
  68.     if (!comma)
  69.         fprintf(file, "void");
  70. }
  71.  
  72. /****************************************************************************************************************/
  73. /*****                                                                                                        *****/
  74. /**                                                WriteDeclarations                                                **/
  75. /*****                                                                                                        *****/
  76. /****************************************************************************************************************/
  77.  
  78. static void WriteDeclarations(FILE *file,ULONG varnb,int vartype)
  79. {
  80.     int        i;
  81.     char    *varname;
  82.     ULONG    type, size;
  83.     char    *typename;
  84.     int        nb_ident = 1;
  85.     char    *buffer = NULL;
  86.     char    *buffer2 = NULL;
  87.  
  88.     typename = STR_type[ vartype - 1 ];        /* find the name 'BOOL ...'    */
  89.     for(i=0;i<varnb;i++)
  90.     {
  91.         MB_GetVarInfo (i,
  92.                        MUIB_VarType, &type,
  93.                        MUIB_VarName, &varname,
  94.                        MUIB_VarSize, &size,
  95.                        TAG_END
  96.                        );
  97.  
  98.         if (type == vartype)
  99.         {
  100.             switch(type)
  101.             {
  102.                 case TYPEVAR_TABSTRING:
  103.                     fprintf(file, "\t%s\t%s[%d];\n",
  104.                              typename,
  105.                              varname,
  106.                              size+1
  107.                            );
  108.                     break;
  109.  
  110.                 case TYPEVAR_IDENT:
  111.                     fprintf(file,"#define %s %d\n", varname, nb_ident++);
  112.                     break;
  113.     
  114.                 case TYPEVAR_LOCAL_PTR:
  115.                     if (!buffer)
  116.                     {
  117.                         if (!(buffer = AllocMemory(strlen(typename)+strlen(varname)+3)))
  118.                         {
  119.                             fclose(file);
  120.                             Quit();
  121.                         }    
  122.                         sprintf(buffer, "\t%s\t%s", typename, varname);
  123.                     }
  124.                     else
  125.                     {
  126.                         buffer2 = buffer;
  127.                         if (!(buffer = AllocMemory(strlen(buffer)+strlen(varname)+3)))
  128.                         {
  129.                             fclose(file);
  130.                             FreeMemory(buffer2);
  131.                             Quit();
  132.                         }    
  133.                         sprintf(buffer,"%s, %s",buffer2,varname);
  134.                         FreeMemory(buffer2);
  135.                     }
  136.                     if (strlen(buffer)>=70)
  137.                     {
  138.                         fprintf(file, "%s;\n", buffer);
  139.                         FreeMemory(buffer);
  140.                         buffer = NULL;
  141.                     }
  142.                     break;
  143.  
  144.                 case TYPEVAR_HOOK:
  145.                     fprintf(file, "\tstatic struct Hook %sHook;\n", varname);
  146.                     break;
  147.  
  148.                 default:
  149.                     fprintf(file, "\t%s\t%s;\n",typename, varname);
  150.                     break;
  151.             }
  152.         }
  153.     }
  154.  
  155.     if (buffer && strlen(buffer)>0)
  156.         fprintf(file, "%s;\n", buffer);
  157.  
  158.     FreeMemory(buffer);
  159. }
  160.  
  161. /****************************************************************************************************************/
  162. /*****                                                                                                        *****/
  163. /**                                            WriteInitialisations                                               **/
  164. /*****                                                                                                        *****/
  165. /****************************************************************************************************************/
  166.  
  167. static void WriteInitialisations(FILE *file,ULONG varnb,int vartype,BOOL Locale,char *GetMBString)
  168. {
  169.     int        i, j;
  170.     ULONG    type, size;
  171.     char    *inits, *name;
  172.     BOOL    enter = FALSE;
  173.  
  174.     for(i=0;i<varnb;i++)
  175.     {
  176.         MB_GetVarInfo(i,
  177.                        MUIB_VarType    , &type,
  178.                        MUIB_VarName    , &name,
  179.                        MUIB_VarSize    , &size,
  180.                        MUIB_VarInitPtr    , &inits,
  181.                        TAG_END
  182.                       );
  183.  
  184.         if (type == vartype)
  185.         {
  186.             enter = TRUE;
  187.             switch(type)
  188.             {
  189.                 case TYPEVAR_TABSTRING:
  190.                     for(j=0;j<size;j++)
  191.                     {
  192.                         if (!Locale)
  193.                              fprintf(file, "\tObject->%s[%d] = \"%s\";\n", name, j, inits);
  194.                         else
  195.                             fprintf(file, "\tObject->%s[%d] = %s(%s);\n", name, j, GetMBString, inits);
  196.                         inits = inits + strlen(inits) + 1;
  197.                     }
  198.                     fprintf(file, "\tObject->%s[%d] = NULL;\n", name, j);
  199.                     break;
  200.  
  201.                 case TYPEVAR_STRING:
  202.                      if (*inits != 0)
  203.                     {
  204.                         if (!Locale)
  205.                              fprintf(file, "\tObject->%s = \"%s\";\n", name, inits);
  206.                         else
  207.                                fprintf(file, "\tObject->%s = %s(%s);\n", name, GetMBString, inits);
  208.                     }
  209.                     else 
  210.                         fprintf(file, "\tObject->%s = NULL;\n", name);
  211.                     break;
  212.  
  213.                 case TYPEVAR_HOOK:
  214.                     fprintf(file, "\tInstallHook(&%sHook,%s,NULL);\n", name, name);
  215.                     break;
  216.  
  217.                 default:
  218.                     break;
  219.             }
  220.         }
  221.     }
  222.  
  223.     if (enter)
  224.         fprintf(file, "\n");
  225. }
  226.  
  227. /****************************************************************************************************************/
  228. /*****                                                                                                        *****/
  229. /**                                                WriteCode                                                        **/
  230. /*****                                                                                                        *****/
  231. /****************************************************************************************************************/
  232.  
  233. static void WriteCode(FILE *file,char *GetString,char *GetMBString)
  234. {
  235.     ULONG    type;
  236.     char*    code;
  237.     BOOL    InFunction     = FALSE;
  238.     BOOL    IndentFunction = TRUE ;
  239.     BOOL    obj_function;
  240.     BOOL    InObj;
  241.     int        nb_indent      = 1;
  242.     int        nb_function    = 0;
  243.     int        name;
  244.  
  245.     MB_GetNextCode(&type, &code);
  246.     while(type != -1)
  247.     {
  248.         switch(type)
  249.         {
  250.             case TC_CREATEOBJ:
  251.                 name = atoi(code);
  252.                 fprintf(file, "%s,\n",MUIStrings[name]);
  253.                 nb_indent++;
  254.                 IndentFunction = TRUE;
  255.                 MB_GetNextCode(&type, &code);
  256.                 InObj = TRUE;
  257.                 break;
  258.  
  259.             case TC_ATTRIBUT:
  260.                 Indent(file,nb_indent);
  261.                 name = atoi(code);
  262.                 fprintf(file, "%s, ",MUIStrings[name]);
  263.                 IndentFunction = FALSE;
  264.                 MB_GetNextCode(&type, &code);
  265.                 break;
  266.  
  267.             case TC_END:
  268.                 nb_indent--;
  269.                 InObj = FALSE;
  270.                 Indent(file,nb_indent);
  271.                 name = atoi(code);
  272.                 fprintf(file, "%s",MUIStrings[name]);
  273.                 IndentFunction = TRUE;
  274.                 MB_GetNextCode(&type, &code);
  275.                 fprintf(file, ";\n\n");
  276.                 break;
  277.  
  278.             case TC_MUIARG_OBJFUNCTION:
  279.                 if (IndentFunction)
  280.                      Indent(file,nb_indent);
  281.                 nb_function++;
  282.                 name = atoi(code);
  283.                 fprintf(file, "%s(",MUIStrings[name]);
  284.                 IndentFunction = FALSE;
  285.                 MB_GetNextCode(&type, &code);
  286.                 obj_function = TRUE;
  287.                 InFunction = TRUE;
  288.                 break;
  289.  
  290.             case TC_MUIARG_FUNCTION:
  291.             case TC_FUNCTION:
  292.                 if (IndentFunction) 
  293.                     Indent(file,nb_indent);
  294.                 nb_function++;
  295.                 name = atoi(code);
  296.                 fprintf(file, "%s(",MUIStrings[name]);
  297.                 IndentFunction = FALSE;
  298.                 InFunction     = TRUE;
  299.                 MB_GetNextCode(&type, &code);
  300.                 obj_function = FALSE;
  301.                 break;
  302.  
  303.             case TC_OBJFUNCTION:
  304.                 if (IndentFunction) 
  305.                     Indent(file,nb_indent);
  306.                 nb_function++;
  307.                 name = atoi(code);
  308.                 fprintf(file, "%s(",MUIStrings[name]);
  309.                 InFunction     = TRUE;
  310.                 IndentFunction = FALSE;
  311.                 MB_GetNextCode(&type,&code);
  312.                 obj_function = TRUE;
  313.                 break;
  314.  
  315.             case TC_STRING:
  316.                 fprintf(file, "\"%s\"",code);
  317.                 MB_GetNextCode(&type, &code);
  318.                 IndentFunction = TRUE;
  319.                 if (InFunction)
  320.                 {
  321.                     if (type  != TC_END_FUNCTION) 
  322.                         fprintf(file, ", ");
  323.                     IndentFunction = FALSE;
  324.                 }
  325.                 else    
  326.                     fprintf(file, ",\n");
  327.                 break;
  328.     
  329.             case TC_LOCALESTRING:
  330.                 fprintf(file, "%s(%s)",GetMBString, code);
  331.                 MB_GetNextCode(&type, &code);
  332.                 IndentFunction = TRUE;
  333.                 if (InFunction)
  334.                 {
  335.                      if (type  != TC_END_FUNCTION)
  336.                          fprintf(file, ", ");
  337.                       IndentFunction = FALSE;
  338.                  }
  339.                 else    
  340.                     fprintf(file, ",\n");
  341.                 break;
  342.  
  343.             case TC_LOCALECHAR:
  344.                 fprintf(file, "%s(%s)[0]",GetString, code);
  345.                 MB_GetNextCode(&type, &code);
  346.                 IndentFunction = TRUE;
  347.                 if (InFunction)
  348.                 {
  349.                     if (type  != TC_END_FUNCTION) 
  350.                         fprintf(file, ", ");
  351.                     IndentFunction = FALSE;
  352.                 }
  353.                 else    
  354.                     fprintf(file, ",\n");
  355.                 break;
  356.  
  357.             case TC_INTEGER:
  358.                 fprintf(file, "%s", code);
  359.                 MB_GetNextCode(&type, &code);
  360.                 IndentFunction = TRUE;
  361.                 if (InFunction)
  362.                 {
  363.                     if (type  != TC_END_FUNCTION) 
  364.                         fprintf(file, ", ");
  365.                     IndentFunction = FALSE;
  366.                 }
  367.                 else    
  368.                     fprintf(file, ",\n");
  369.                 break;
  370.  
  371.             case TC_CHAR:
  372.                 fprintf(file, "'%s'",code);
  373.                 MB_GetNextCode(&type, &code);
  374.                 IndentFunction = TRUE;
  375.                 if (InFunction)
  376.                 {
  377.                     if (type  != TC_END_FUNCTION) 
  378.                         fprintf(file, ", ");
  379.                     IndentFunction = FALSE;
  380.                 }
  381.                 else    
  382.                     fprintf(file, ",\n");
  383.                 break;    
  384.  
  385.             case TC_VAR_AFFECT:
  386.                 name = atoi(code);
  387.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  388.                 if (type == TYPEVAR_LOCAL_PTR) 
  389.                     fprintf( file, "\t%s = ", code);
  390.                 else 
  391.                     fprintf(file, "\tObject->%s = ", code); 
  392.                 IndentFunction = FALSE;
  393.                 MB_GetNextCode(&type, &code);
  394.                 break;
  395.  
  396.             case TC_OBJ_ARG:
  397.             case TC_VAR_ARG:
  398.                 name = atoi(code);
  399.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  400.                 if (type == TYPEVAR_LOCAL_PTR) 
  401.                     fprintf(file, "%s", code);
  402.                 else                   
  403.                     fprintf(file, "Object->%s", code);
  404.                 MB_GetNextCode(&type, &code);
  405.                 if ((InFunction)&&(type != TC_END_FUNCTION)) 
  406.                     fprintf(file, ", ");
  407.                 if (!InFunction)
  408.                 {
  409.                     fprintf(file, ",\n");
  410.                     IndentFunction = TRUE;
  411.                 }
  412.                 break;
  413.  
  414.             case TC_END_FUNCTION:
  415.                 MB_GetNextCode(&type, &code);
  416.                 if (nb_function>1)
  417.                 {
  418.                     if (type != TC_END_FUNCTION) 
  419.                         fprintf(file, "),");
  420.                     else                 
  421.                         fprintf(file, ")");
  422.                 }    
  423.                 else
  424.                 {
  425.                     if (obj_function) 
  426.                         fprintf(file, ");\n\n");
  427.                     else          
  428.                         fprintf(file, "),\n");
  429.                     IndentFunction = TRUE;
  430.                     InFunction     = FALSE;
  431.                     obj_function   = FALSE;
  432.                 }
  433.                 nb_function--;
  434.                 break;
  435.  
  436.             case TC_BOOL:
  437.                 if (*code == '0')    
  438.                     fprintf(file, "FALSE");
  439.                 else            
  440.                     fprintf(file, "TRUE" );
  441.                 MB_GetNextCode(&type, &code);
  442.                 if (InFunction)
  443.                 {
  444.                     if (type != TC_END_FUNCTION)
  445.                     {
  446.                         fprintf(file, ", ");
  447.                         IndentFunction = FALSE;
  448.                     }
  449.                 }
  450.                 else 
  451.                     fprintf(file, ",\n");
  452.                 break;
  453.  
  454.             case TC_MUIARG:
  455.                 if (IndentFunction) 
  456.                     Indent(file,nb_indent);
  457.                 name = atoi(code);
  458.                 fprintf(file, "%s", MUIStrings[name]);
  459.                 MB_GetNextCode(&type, &code);
  460.                 if (InFunction)
  461.                 {
  462.                     if (type != TC_END_FUNCTION)
  463.                     {
  464.                         fprintf(file, ", ");
  465.                         IndentFunction = FALSE;
  466.                     }
  467.                 }
  468.                 else
  469.                 {
  470.                     fprintf(file, ",\n");
  471.                     IndentFunction = TRUE;
  472.                 }
  473.                 break;
  474.  
  475.             case TC_MUIARG_ATTRIBUT:
  476.                 if (IndentFunction) 
  477.                     Indent(file,nb_indent);
  478.                 name = atoi(code);
  479.                 MB_GetNextCode(&type, &code);
  480.                 if (InObj) 
  481.                     fprintf(file, "%s,\n", MUIStrings[name]);
  482.                 else
  483.                 {
  484.                     if (InFunction)
  485.                     {
  486.                         if (type != TC_END_FUNCTION)
  487.                             fprintf(file, "%s,", MUIStrings[name]);
  488.                         else    
  489.                             fprintf(file, "%s", MUIStrings[name]);
  490.                     }
  491.                     else
  492.                         fprintf(file, "%s;\n\n", MUIStrings[name]);
  493.                 }
  494.                 break;
  495.  
  496.             case TC_MUIARG_OBJ:
  497.                 if (IndentFunction) 
  498.                     Indent(file,nb_indent);
  499.                 name = atoi(code);
  500.                 MB_GetNextCode(&type, &code);
  501.                 fprintf(file, "%s;\n\n", MUIStrings[name]);
  502.                 break;
  503.  
  504.             case TC_EXTERNAL_FUNCTION:
  505.                 fprintf(file, "&%sHook", code);
  506.                 MB_GetNextCode(&type, &code);
  507.                 if (InFunction)
  508.                 {
  509.                     if (type != TC_END_FUNCTION)    
  510.                     {
  511.                         fprintf(file, ", ");
  512.                         IndentFunction = FALSE;
  513.                     }
  514.                 }
  515.                 else
  516.                 {
  517.                     fprintf(file, ",\n");
  518.                     IndentFunction = TRUE;
  519.                 }
  520.                 break;
  521.  
  522.             default:
  523.             {
  524.                 char    msg[80];
  525.  
  526.                 sprintf(msg,"Type = %d\nERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n", type);
  527.                 DisplayMsg(msg);
  528.                 Quit();
  529.             }
  530.             break;
  531.         }
  532.     }
  533. }
  534.  
  535. /****************************************************************************************************************/
  536. /*****                                                                                                        *****/
  537. /**                                                WriteNotify                                                        **/
  538. /*****                                                                                                        *****/
  539. /****************************************************************************************************************/
  540.  
  541. static void WriteNotify(FILE *file,char *GetString,char *GetMBString)
  542. {
  543.     ULONG    type;
  544.     char*    code;
  545.     int        name;
  546.     BOOL    indent = FALSE;
  547.  
  548.     fprintf(file, "\n");
  549.     MB_GetNextNotify(&type, &code);
  550.     while(type != -1)
  551.     {
  552.         if (indent) 
  553.             fprintf(file, "\t\t");
  554.         indent = TRUE;
  555.         switch(type)
  556.         {
  557.             case TC_END_FUNCTION:
  558.             case TC_END_NOTIFICATION:
  559.                 fprintf(file, ");\n\n");
  560.                 MB_GetNextNotify(&type, &code);
  561.                 indent = FALSE;
  562.                 break;
  563.  
  564.             case TC_BEGIN_NOTIFICATION:
  565.                 name = atoi(code);
  566.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  567.                 if (type == TYPEVAR_LOCAL_PTR) 
  568.                     fprintf(file, "\tDoMethod(%s,\n", code);
  569.                 else
  570.                     fprintf(file, "\tDoMethod(Object->%s,\n", code);
  571.                 MB_GetNextNotify(&type, &code);
  572.                 break;
  573.  
  574.             case TC_FUNCTION:
  575.                 name = atoi(code);
  576.                 fprintf(file, "\t%s(", MUIStrings[name]);
  577.                 MB_GetNextNotify(&type, &code);
  578.                 indent = FALSE;
  579.                 break;
  580.  
  581.             case TC_STRING:
  582.                 fprintf(file, "\"%s\"",code);
  583.                 MB_GetNextNotify(&type, &code);
  584.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))  
  585.                     fprintf(file, ",\n");
  586.                 else 
  587.                     fprintf(file, "\n");
  588.                 break;
  589.  
  590.             case TC_LOCALESTRING:
  591.                 fprintf(file, "%s(%s)",GetMBString, code);
  592.                 MB_GetNextNotify(&type, &code);
  593.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  594.                     fprintf(file, ",\n");
  595.                 else 
  596.                     fprintf(file, "\n");
  597.                 break;
  598.  
  599.             case TC_LOCALECHAR:
  600.                 fprintf(file, "%s(%s)[0]",GetString, code);
  601.                 MB_GetNextNotify(&type, &code);
  602.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  603.                     fprintf(file, ",\n");
  604.                 else 
  605.                     fprintf(file, "\n");
  606.                 break;
  607.  
  608.             case TC_INTEGER:
  609.                 fprintf(file, "%s", code);
  610.                 MB_GetNextNotify(&type, &code);
  611.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  612.                     fprintf(file, ",\n");
  613.                 else 
  614.                     fprintf(file, "\n");
  615.                 break;
  616.  
  617.             case TC_CHAR:
  618.                 fprintf(file, "'%s'",code);
  619.                 MB_GetNextNotify(&type, &code);
  620.                 if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  621.                     fprintf(file, ",\n");
  622.                 else 
  623.                     fprintf(file, "\n");
  624.                 break;
  625.     
  626.             case TC_VAR_ARG:
  627.                 name = atoi(code);
  628.                 MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  629.                 if ((type==TYPEVAR_LOCAL_PTR)||(type==TYPEVAR_EXTERNAL_PTR)) 
  630.                     fprintf(file, "%s", code);
  631.                 else
  632.                     fprintf(file, "Object->%s", code);
  633.                 MB_GetNextNotify(&type, &code);
  634.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  635.                     fprintf(file, ",\n");
  636.                 else 
  637.                     fprintf(file, "\n");
  638.                 break;
  639.  
  640.             case TC_BOOL:
  641.                 if (*code == '0')    
  642.                     fprintf(file, "FALSE");
  643.                 else            
  644.                     fprintf(file, "TRUE" );
  645.                 MB_GetNextNotify(&type, &code);
  646.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  647.                     fprintf(file, ",\n");
  648.                 else 
  649.                     fprintf(file, "\n");
  650.                 break;
  651.  
  652.             case TC_MUIARG:
  653.             case TC_MUIARG_OBJ:
  654.                 name = atoi(code);
  655.                 fprintf(file, "%s", MUIStrings[name]);
  656.                 MB_GetNextNotify(&type, &code);
  657.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  658.                     fprintf(file, ", ");
  659.                 indent = FALSE;
  660.                 break;
  661.  
  662.             case TC_MUIARG_ATTRIBUT:
  663.                 name = atoi(code);
  664.                 fprintf(file, "%s", MUIStrings[name]);
  665.                 MB_GetNextNotify(&type, &code);
  666.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  667.                     fprintf(file, ",\n");
  668.                 else 
  669.                     fprintf(file, "\n");
  670.                 break;
  671.  
  672.             case TC_EXTERNAL_CONSTANT:
  673.                 fprintf(file, "%s", code);
  674.                 MB_GetNextNotify(&type, &code);
  675.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  676.                     fprintf(file, ",\n");
  677.                 else 
  678.                     fprintf(file, "\n");
  679.                 break;
  680.  
  681.             case TC_EXTERNAL_FUNCTION:
  682.                 fprintf(file, "&%sHook", code);
  683.                 MB_GetNextNotify(&type, &code);
  684.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  685.                     fprintf(file, ",\n");
  686.                 else 
  687.                     fprintf(file, "\n");
  688.                 break;
  689.  
  690.             case TC_EXTERNAL_VARIABLE:
  691.                 fprintf(file, "%s", code);
  692.                 MB_GetNextNotify(&type, &code);
  693.                 if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  694.                     fprintf(file, ",\n");
  695.                 else 
  696.                     fprintf(file, "\n");
  697.                 break;
  698.  
  699.             default:
  700.             {
  701.                 char msg[80];
  702.  
  703.                 sprintf(msg,"Type = %d\nERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n", type);
  704.                 DisplayMsg(msg);
  705.                 Quit();
  706.             }
  707.             break;
  708.         }
  709.     }
  710. }
  711.  
  712. /****************************************************************************************************************/
  713. /*****                                                                                                        *****/
  714. /**                                                 WriteHeaderFile                                                   **/
  715. /*****                                                                                                        *****/
  716. /****************************************************************************************************************/
  717.  
  718. void WriteHeaderFile(char *HeaderFile,char *HHeaderText,char *FileName,ULONG varnb,
  719.                      BOOL Env,BOOL Notifications,BOOL Locale)
  720. {
  721.     char    *name;
  722.     FILE    *file;
  723.  
  724.     file = fopen(HeaderFile, "w+");
  725.     if (file)
  726.     {
  727.         fprintf(file,"#ifndef GUI_FILE_H\n");
  728.         fprintf(file,"#define GUI_FILE_H\n\n");
  729.         if (Env)
  730.             fprintf(file,"%s",HHeaderText);
  731.         if (Locale)
  732.             fprintf(file, "#include \"%s_cat.h\"\n\n",FilePart(FileName));
  733.         MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END);
  734.         fprintf(file, "struct Obj%s\n{\n", name);
  735.         WriteDeclarations(file,varnb,TYPEVAR_PTR);
  736.         WriteDeclarations(file,varnb,TYPEVAR_BOOL);
  737.         WriteDeclarations(file,varnb,TYPEVAR_INT);
  738.         WriteDeclarations(file,varnb,TYPEVAR_STRING);
  739.         WriteDeclarations(file,varnb,TYPEVAR_TABSTRING);
  740.         fprintf(file, "};\n\n");
  741.         if (Notifications)
  742.         {
  743.             WriteDeclarations(file,varnb,TYPEVAR_IDENT);
  744.             fprintf(file, "\n");
  745.         }
  746.         if (Env)
  747.         {
  748.             fprintf(file,"extern struct Obj%s * Create%s(",name,name);
  749.             WriteParameters(file,varnb,Notifications);
  750.             fprintf(file,");\n");
  751.             fprintf(file,"extern void Dispose%s(struct Obj%s *);\n", name, name);
  752.         }
  753.         fprintf(file,"\n#endif\n");
  754.         fclose(file);
  755.     }
  756. }
  757.  
  758. /****************************************************************************************************************/
  759. /*****                                                                                                        *****/
  760. /**                                             WriteGUIFile                                                       **/
  761. /*****                                                                                                        *****/
  762. /****************************************************************************************************************/
  763.  
  764. void WriteGUIFile(char *MBDir,char *HeaderFile,char *GUIFile,char *CHeaderText,
  765.                   char *Externals,char *GetString,char *GetMBString,
  766.                   ULONG varnb,
  767.                   BOOL ExternalExist,BOOL Env,BOOL Locale,BOOL Declarations,BOOL Code,BOOL Notifications)
  768. {
  769.     char                            *name;
  770.     FILE                            *file;
  771.     char                            *FromHookfile;
  772.     char                            *ToHookfile;
  773.     int                                i;
  774.     ULONG                            type;
  775.     size_t                            length;
  776.     BOOL                            HookExist;
  777.  
  778.     if (file = fopen(GUIFile, "w+"))
  779.     {
  780.         if (Env)
  781.         {
  782.             fprintf(file,"%s",CHeaderText);
  783.             MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END);
  784.             fprintf(file, "\n#include \"%s\"\n", FilePart(HeaderFile));
  785.             if (ExternalExist) 
  786.                 fprintf(file, "#include \"%s\"\n", FilePart(Externals));
  787.             for(i = 0, HookExist = FALSE; !HookExist && i<varnb;i++)
  788.             {
  789.                 MB_GetVarInfo (i,MUIB_VarType, &type, TAG_END);
  790.                 HookExist = (type == TYPEVAR_HOOK);
  791.             }
  792.             if (HookExist)
  793.             {
  794.                 fprintf(file, "#include \"Hook_utility.h\"");
  795.  
  796.                 /* Copy Utility_Hook.h in current directory */
  797.                 if (!(FromHookfile=AllocMemory(strlen(MBDir)+14+2)))
  798.                 {
  799.                     fclose(file);
  800.                     Quit();
  801.                 }
  802.                 strcpy(FromHookfile,MBDir);
  803.                 AddPart(FromHookfile,"Hook_utility.h",strlen(MBDir)+14+2);
  804.  
  805.                 length=(size_t)(FilePart(GUIFile)-GUIFile);
  806.                 if (!(ToHookfile=AllocMemory(length+14+2)))
  807.                 {
  808.                     fclose(file);
  809.                     FreeMemory(FromHookfile);
  810.                     Quit();
  811.                 }
  812.                 strncpy(ToHookfile,GUIFile,length);
  813.                 ToHookfile[length]='\0';
  814.                 AddPart(ToHookfile,"Hook_utility.h",length+14+2);
  815.  
  816.                 if (!(CopyFile(FromHookfile,ToHookfile)))
  817.                 {
  818.                     fclose(file);
  819.                     FreeMemory(FromHookfile);
  820.                     FreeMemory(ToHookfile);
  821.                     Quit();
  822.                 }
  823.  
  824.                 /* Copy Hook_utility.o in current directory */
  825.                 strcpy(FromHookfile,MBDir);
  826.                 AddPart(FromHookfile,"Hook_utility.o",strlen(MBDir)+14+2);
  827.  
  828.                 strncpy(ToHookfile,GUIFile,length);
  829.                 ToHookfile[length]='\0';
  830.                 AddPart(ToHookfile,"Hook_utility.o",length+14+2);
  831.  
  832.                 if (!(CopyFile(FromHookfile,ToHookfile)))
  833.                 {
  834.                     fclose(file);
  835.                     FreeMemory(FromHookfile);
  836.                     FreeMemory(ToHookfile);
  837.                     Quit();
  838.                 }
  839.                 FreeMemory(FromHookfile);
  840.                 FreeMemory(ToHookfile);
  841.             }
  842.             if (Locale)
  843.               {
  844.                 fprintf(file, "\nstatic char *%s(APTR ref)\n{\n", GetMBString);
  845.                 fprintf(file, "\tchar *aux;\n\n");
  846.                 fprintf(file, "\taux = %s(ref);\n", GetString);
  847.                 fprintf(file, "\tif (aux[1] == '\\0') return(&aux[2]);\n");
  848.                 fprintf(file, "\telse                return(aux);\n}\n");
  849.               }
  850.             fprintf(file, "\nstruct Obj%s * Create%s(", name, name);
  851.             WriteParameters(file,varnb,Notifications);
  852.             fprintf(file, ")\n");
  853.             fprintf(file, "{\n\tstruct Obj%s * Object;\n\n", name);
  854.         }
  855.         if (Declarations)
  856.         {
  857.             WriteDeclarations(file,varnb,TYPEVAR_LOCAL_PTR);
  858.             if (HookExist)
  859.                 WriteDeclarations(file,varnb,TYPEVAR_HOOK);
  860.         }
  861.         if (Env) 
  862.             fprintf(file, "\n\tif (!(Object = AllocVec(sizeof(struct Obj%s),MEMF_PUBLIC|MEMF_CLEAR)))\n\t\treturn(NULL);\n\n", name);
  863.         if (Declarations)
  864.         {
  865.             WriteInitialisations(file,varnb,TYPEVAR_STRING,Locale,GetMBString);
  866.             WriteInitialisations(file,varnb,TYPEVAR_TABSTRING,Locale,GetMBString);
  867.             if (HookExist)
  868.                 WriteInitialisations(file,varnb,TYPEVAR_HOOK,Locale,GetMBString);
  869.         }
  870.         if (Code) 
  871.             WriteCode(file,GetString,GetMBString);
  872.         if (Env)
  873.         {
  874.             fprintf(file, "\n\tif (!Object->%s)\n\t{\n\t\tFreeVec(Object);", name);
  875.             fprintf(file, "\n\t\treturn(NULL);\n\t}\n");
  876.         }
  877.         if (Notifications)
  878.             WriteNotify(file,GetString,GetMBString);
  879.         if (Env)
  880.         {
  881.             fprintf(file, "\n\treturn(Object);\n}\n");
  882.             fprintf(file, "\nvoid Dispose%s(struct Obj%s * Object)\n{\n", name, name);
  883.             fprintf(file, "\tMUI_DisposeObject(Object->%s);\n", name);
  884.             fprintf(file, "\tFreeVec(Object);\n}\n");
  885.         }
  886.         fclose(file);
  887.     }
  888.     else 
  889.         DisplayMsg("Unable to open GUI-File !\n");
  890. }
  891.